package 贪心;

/**
 * @ClassName _53最大子序列
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/12/8 20:19
 * Version 1.0
 **/
public class _53最大子数组和 {
    public static void main(String[] args) {
        int a[] = new int[]{-2,1,-3,4,-1,2,1,-5,4};

    }
    public int maxSubArray(int[] nums) {
        if(nums.length == 1){
            return nums[0];
        }
        int sum = 0,max = Integer.MIN_VALUE;
        for(int i = 0; i < nums.length; i++){
            sum += nums[i];
            max = sum > max ? sum : max;
            if(sum < 0){
                sum = 0;
            }
        }
        return max;
    }
}
